package com.basic.business.dingTalk.controller;


import com.basic.business.dingTalk.domain.TDingTalkMgmt;
import com.basic.business.dingTalk.service.ITDingTalkMgmtService;
import com.basic.common.annotation.FileExport;
import com.basic.common.annotation.Log;
import com.basic.common.core.controller.BaseController;
import com.basic.common.core.domain.AjaxResult;
import com.basic.common.core.page.TableDataInfo;
import com.basic.common.enums.BusinessType;
import com.basic.common.utils.easyExcel.EasyExcelUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

/**
 * 钉钉配置Controller
 * 
 * @author zhaoxy_jn@163.com
 */
@RestController
@RequestMapping("/business/dingTalk")
public class TDingTalkMgmtController extends BaseController
{
    @Resource
    private ITDingTalkMgmtService tDingTalkMgmtService;

    /**
     * 查询钉钉配置列表
     */
    @PreAuthorize("@ss.hasPermi('business:dingTalk:list')")
    @GetMapping("/list")
    public TableDataInfo list(TDingTalkMgmt tDingTalkMgmt)
    {
        startPage();
        List<TDingTalkMgmt> list = tDingTalkMgmtService.getList(tDingTalkMgmt);
        return getDataTable(list);
    }

    /**
     * 导出钉钉配置列表
     */
    @PreAuthorize("@ss.hasPermi('business:dingTalk:export')")
    @Log(title = "钉钉配置", businessType = BusinessType.EXPORT)
    @FileExport(fileName = "钉钉配置.xlsx")
    @PostMapping("/export")
    public String export(TDingTalkMgmt tDingTalkMgmt) throws IOException
    {
        List<TDingTalkMgmt> list = tDingTalkMgmtService.getList(tDingTalkMgmt);
        return EasyExcelUtils.excelExport(TDingTalkMgmt.class,"钉钉配置数据", list);
    }

    /**
     * 获取钉钉配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:dingTalk:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tDingTalkMgmtService.get(id));
    }

    /**
     * 新增钉钉配置
     */
    @PreAuthorize("@ss.hasPermi('business:dingTalk:add')")
    @Log(title = "钉钉配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TDingTalkMgmt tDingTalkMgmt)
    {
        return toAjax(tDingTalkMgmtService.insert(tDingTalkMgmt));
    }

    /**
     * 修改钉钉配置
     */
    @PreAuthorize("@ss.hasPermi('business:dingTalk:edit')")
    @Log(title = "钉钉配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TDingTalkMgmt tDingTalkMgmt)
    {
        return toAjax(tDingTalkMgmtService.update(tDingTalkMgmt));
    }

    /**
     * 删除钉钉配置
     */
    @PreAuthorize("@ss.hasPermi('business:dingTalk:remove')")
    @Log(title = "钉钉配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tDingTalkMgmtService.deleteByIds(ids));
    }

    /**
     * 刷新缓存
     */
    @PreAuthorize("@ss.hasPermi('business:dingTalk:refreshCache')")
    @Log(title = "钉钉配置", businessType = BusinessType.CLEAN)
    @DeleteMapping("/refreshCache")
    public AjaxResult refreshCache()
    {
        tDingTalkMgmtService.resetDingTalkCache();
        return success();
    }
}
